package com.liaoban.app.ui.common;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.liaoban.app.R;
import com.liaoban.app.api.type.event.WxPayResultEvent;
import com.liaoban.app.constants.ExtraParam;
import com.liaoban.app.ui.base.BaseToolbarActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ybc on 2018/5/1 0001.
 * 支付结果
 */

public class PayResultActivity extends BaseToolbarActivity {
    @BindView(R.id.tv_result)
    TextView tvResult;

    private int mErrCode;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_pay_result;
    }

    public static Intent newIntent(Context context, int code) {
        Intent intent = new Intent(context, PayResultActivity.class);
        intent.putExtra(ExtraParam.CODE, code);
        return intent;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mErrCode = getIntent().getIntExtra(ExtraParam.CODE, -1);
        switch (mErrCode) {
            case 0: //成功
                EventBus.getDefault().post(new WxPayResultEvent());
                tvResult.setText("支付成功");
                break;
            case -1: //失败
                tvResult.setText("支付失败");
                break;
            case -2: //取消支付
                tvResult.setText("取消支付");
                break;
            default:
                tvResult.setText("支付失败");
                break;
        }
    }

    @Override
    protected String getNewTitle() {
        return "支付结果";
    }
}
